package com.lyj.controller;

import com.lyj.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * Created by lyj on 2018/11/15.
 */
@RestController
@RequestMapping("/consumer/user")
public class OrderConsumerController {

    // 订单服务提供者模块的 url 前缀
    private static final String ORDER_PROVIDER_URL_PREFIX = "http://localhost:81";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/get/{id}")
    public User getOrder(@PathVariable Long id) {

        return restTemplate.getForObject(ORDER_PROVIDER_URL_PREFIX + "/provider/user/get/" + id, User.class);
    }

    @SuppressWarnings("unchecked")
    @GetMapping("/get/list")
    public List<User> getAll() {
        return restTemplate.getForObject(ORDER_PROVIDER_URL_PREFIX + "/provider/user/get/list", List.class);
    }

}
